<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>


	
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  height:'+(winHeight/1.2)+'px;'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 200px;">key check :  </span>
				<div>
					<el-button size="mini" type="success" @click="get_exchange_arrange()">刷新</el-button>
					<el-button size="mini" type="primary" @click="addnew_account()">新增</el-button>
					
				</div>

				<span style="font-size: medium; padding: 10px;">server:</span>
				<el-select v-model="server_choice" size="small" clearable filterable placeholder="请选择"
					@change="get_exchange_arrange()">
					<el-option v-for="item in server_list" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>

				
			</div>
<!-- id|name  |server|useflag|local_path|remote_path  |file_name |file_type|sec_name |key_name|include_type |include_priority|update_time        | -->
			<el-table ref="singleTable" :data="arrange_data" height="100%" border size='small' :fit='true'
				:style="'width:'+(screenWidth*1.0)+'px;' ">
				<el-table-column prop="id" label="id"  sortable  align></el-table-column>
				<el-table-column prop="name" label="name"  sortable align></el-table-column>
				<el-table-column prop="server" label="server"  sortable  align></el-table-column>
				<el-table-column prop="useflag" label="useflag"  sortable  align></el-table-column>
				
				<el-table-column prop="file_name" label="file_name" width="250"    align></el-table-column>
				<el-table-column prop="file_type" label="file_type"  sortable  align></el-table-column>
				<el-table-column prop="sec_name" label="sec_name"  sortable  align></el-table-column>
				<el-table-column prop="key_name" label="key_name"   sortable  align></el-table-column>
				<el-table-column prop="include_type" label="include_type"   align></el-table-column>
				<el-table-column prop="include_priority" label="include_priority"   align></el-table-column>
				
				<el-table-column prop="update_time1" label="update_time" disabled sortable  align></el-table-column>
				<el-table-column prop="local_path" label="local_path"  width="450"  align></el-table-column>
				<el-table-column prop="remote_path" label="remote_path"  width="350"   align></el-table-column>
				<el-table-column label="操作" :width='90'>
					<template slot-scope="scope">
						<el-button size="mini" type="primary" @click="handlefixaccount(scope.$index, scope.row,'binary')">修改
						</el-button>
					</template>
				</el-table-column>
				<el-table-column label="删除" :width='90'>
					<template slot-scope="scope">
						<el-button size="mini" type="danger" @click="delete_account(scope.$index, scope.row)">删除
						</el-button>
					</template>
				</el-table-column>
				
		
		
			</el-table>

		</div>
		<!-- id|name  |server|useflag|local_path|remote_path  |file_name |file_type|sec_name |key_name|include_type |include_priority|update_time        | -->
		<el-dialog :visible.sync="visible2">
			<div style="display: flex;flex-flow: column; justify-content:center;">
				<div style="display: flex; justify-content:center;">
					<span style="color: orange;font-size: 24px; font-family: KaiTi, Helvetica, sans-serif;">修改 {{fix_account['id']}}</span>
				</div>
				<div style="display: flex;flex-flow:row; ">
					<div style="width: 100%; height: 600px;overflow-y: scroll;">
					
						
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">id：</span>
							<el-input v-model="fix_account['id']"  disabled size="small" style="width: 70%;"placeholder="id"></el-input>
						</div>	
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">name：</span>
							<el-input v-model="fix_account['name']" size="small" style="width: 70%;"placeholder="name"></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">server：</span>
							<el-select v-model="fix_account['server']" size="small" style="width: 70%;" collapse-tags placeholder="请选择">
								<el-option v-for="item in server_list" :key="item.value" :label="item.label"
									:value="item.value">
								</el-option>
							</el-select>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">useflag：</span>
							<el-select v-model="fix_account['useflag']" size="small" style="width: 70%;" collapse-tags placeholder="请选择">
								<el-option v-for="item in use_options" :key="item.value" :label="item.label"
									:value="item.value">
								</el-option>
							</el-select>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">file_name：</span>
							<el-select v-model="fix_account['file_name']" size="small" style="width: 70%;" allow-create clearable filterable @change="change_file()" collapse-tags placeholder="请选择">
								<el-option v-for="item in file_name_options" :key="item.value" :label="item.label"
									:value="item.value">
								</el-option>
							</el-select>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">local_path：</span>
							<el-input v-model="fix_account['local_path']" size="small" style="width: 70%;"placeholder="local_path"></el-input>
						</div>
							
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">remote_path：</span>
							<el-input v-model="fix_account['remote_path']" size="small" style="width: 70%;"placeholder="remote_path"></el-input>
						</div>
						
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">file_type：</span>
							<el-select v-model="fix_account['file_type']" size="small" style="width: 70%;" collapse-tags placeholder="请选择">
								<el-option v-for="item in type_options" :key="item.value" :label="item.label"
									:value="item.value">
								</el-option>
							</el-select>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">sec_name：</span>
							<el-input v-model="fix_account['sec_name']"  size="small" style="width: 70%;"placeholder="sec_name"></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">key_name：</span>
							<el-input v-model="fix_account['key_name']"  size="small" style="width: 70%;"placeholder="key_name"></el-input>
						</div>
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">include_type：</span>
							<el-input v-model="fix_account['include_type']"  size="small" style="width: 70%;"placeholder="include_type"></el-input>
						</div>
						
						
						
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">include_priority：</span>
							<el-input v-model="fix_account['include_priority']" size="small" style="width: 70%;"placeholder="include_priority"></el-input>
						</div>
						<div style="display: flex;align-items: center;center;padding-top: 20px; justify-content:center;">
							<span style="width: 20%;">update_time：</span>
							<el-input v-model="fix_account['update_time1']" disabled size="small" style="width: 70%;"placeholder="update_time"></el-input>
						</div>
						

						
					
					</div>
					
				</div>
				<div style="display: flex;align-items: center;padding-top: 20px;  justify-content:center">
					<el-button style=" height: 33px;" size="small" type="success" @click="changedata_account()">修改确认</el-button>
				</div>
		
		  
			</div>
		
		
		</el-dialog>
	</div>
</template>

<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				checkflag: false,
				core_pos: [],
				pos_index_item: '',
				server_choice: "",
				product_options: [],
				target_pos_index_options: [],
				date_choice: "",
				date_options: [],
				tableData: [],
				currentRow: null,
				inoutflag:false,
				count: 0,
				exchange_detail: [],
				LP_account_list: [],
				fix_account: {},
				visible: false,
				visible2: false,
				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				moneyindex: "0",
				arrange_data: [],
                file_name_options: [
					{
						value: 'ts_config.ini',
						label: 'ts_config.ini'
					},
					{
						value: 'qs_config_tick.ini',
						label: 'qs_config_tick.ini'
					},
					{
						value: 'query_param_config.json',
						label: 'query_param_config.json'
					},
					{
						value: 'query_param_config_twap.json',
						label: 'query_param_config_twap.json'
					},
					{
						value: 'signal_server_123.ini',
						label: 'signal_server_123.ini'
					},
					{
						value: 'signal_server_4.ini',
						label: 'signal_server_4.ini'
					},
					{
						value: 'signal_server_5.ini',
						label: 'signal_server_5.ini'
					},
					{
						value: 'signal_server_6_1.ini',
						label: 'signal_server_6_1.ini'
					},
					{
						value: 'signal_server_6_2.ini',
						label: 'signal_server_6_2.ini'
					},
					{
						value: 'query_param_config_sg123.json',
						label: 'query_param_config_sg123.json'
					},
					{
						value: 'query_param_config_sg4.json',
						label: 'query_param_config_sg4.json'
					},
					{
						value: 'query_param_config_sg5.json',
						label: 'query_param_config_sg5.json'
					},
					{
						value: 'query_param_config_sg6_1.json,query_param_config_sg6_2.json',
						label: 'query_param_config_sg6_1.json,query_param_config_sg6_2.json'
					},
				],
				
				type_options: [
					{
						value: 'ini',
						label: 'ini'
					},
					{
						value: 'json',
						label: 'json'
					},
					

				],
				
				use_options: [
					{
						value: 'yes',
						label: 'yes'
					},
					{
						value: 'no',
						label: 'no'
					},

				],

			}
		},
		components: {
			headTop,
		},



		activated() {

			// console.log("当前登入用户", this.$store.state.adminInfo.name);
			//    if (this.tradesysPermission_list.indexOf (this.$store.state.adminInfo.permission) ==-1) {
			// 	console.log(this.$store.state.adminInfo.name,"未登入")
			// 	this.$message({type: 'error',	message: '没有权限',});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},
		created() {
			
			this.get_exchange_arrange()
		},
		computed: {
			
		},

		methods: {
			
			
			
			change_file(){
				var that=this
				console.log( that.fix_account['file_name'])
				that.fix_account['remote_path']='/home/admin/prodxx/config/'
				that.fix_account['local_path']='/mnt/nfs_disk_5/ZTLP/config_history/current/'
				switch (that.fix_account['file_name']) {  
				    case "ts_config.ini":
					case "qs_config.ini":
					case "qs_config_tick.ini":
				        that.fix_account['file_type']='ini'
						that.fix_account['sec_name']='COMMON'
						that.fix_account['key_name']='syms'
						that.fix_account['include_type']='ts3'
				        break;  
				    case "signal_server_123.ini":  
					case "signal_server_4.ini":  
					case "signal_server_5.ini":  
				        that.fix_account['file_type']='ini'
				        that.fix_account['sec_name']='COMMON'
				        that.fix_account['key_name']='symbols_spots'
				        that.fix_account['include_type']='ob1' 
				        break;  
				    case "query_param_config_sg123.json":
				    case "query_param_config_sg4.json":  
				    case "query_param_config_sg5.json":
				        that.fix_account['file_type']='json'
				        that.fix_account['sec_name']='Contracts'
				        that.fix_account['key_name']='symbol'
				        that.fix_account['include_type']='ob1' 
				        break;  
					case "query_param_config.json":
					case "query_param_config_twap.json":  
					    that.fix_account['file_type']='json'
					    that.fix_account['sec_name']='Strategy,tactic'
					    that.fix_account['key_name']='volume_limit_per_name'
					    that.fix_account['include_type']='ob1,tick1,ts2' 
					    break;  
					case "signal_server_6_1.ini":
					case "signal_server_6_2.ini":
					    that.fix_account['file_type']='ini'
					    that.fix_account['sec_name']='COMMON'
					    that.fix_account['key_name']='symbols_spots'
					    that.fix_account['include_type']='tick1' 
					    break;  
					case "query_param_config_sg6_1.json,query_param_config_sg6_2.json":
					    that.fix_account['file_type']='json'
					    that.fix_account['sec_name']='Contracts'
					    that.fix_account['key_name']='symbol'
					    that.fix_account['include_type']='tick1' 
					    break;
				    default:  
				}
			},
			
			handlefixaccount(index, row) {
				console.log("row", row)
				this.fix_account = row
				this.visible2 = true
			},

			get_exchange_arrange() {
				var that = this;
				console.log(that.lpapi2)
				let sql = " SELECT  *,   date_format(update_time,'%Y-%m-%d %H:%I:%S') as update_time1   FROM  check_key_consistency pc order by id desc;"
				if (this.server_choice != "") {
					
					sql ="SELECT  *,   date_format(update_time,'%Y-%m-%d %H:%I:%S') as update_time1   FROM  \
					check_key_consistency pc where server = '"+this.server_choice+"' order by id desc;"
				} 
				that.arrange_data = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response.data[0], 'check_key_consistency')
					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data = []
						} else {
							that.arrange_data = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},


			changedata_account(){
				var that = this
				if (this.allow_readpw!='yes' ){
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',inputType: 'password',
						inputType: 'password',
					}).then(({
						value
					}) => {
						if (value == '621890') {
							this.$message({
								type: 'success',
								message: '密码正确:'
							});
							that.allow_readpw='yes'
						} else {
							this.$message({
								type: 'error',
								message: '密码出错'
							});
						}
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});
					});
					return
				}
				
				that.$confirm('此操作将永久修改数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',inputType: 'password',
					type: 'warning'
				}).then(() => {
					let fixdata=that.fix_account
			
					
					
					let sql3 = "UPDATE `check_key_consistency` SET \
						`name` = '" + fixdata['name'] + "', \
						`server` = '" + fixdata['server'] + "', `useflag` = '" + fixdata['useflag'] + "', \
						`local_path` = '" + fixdata['local_path'] + "',   \
						`remote_path` = '" + fixdata['remote_path'] + "', \
						`file_name` = '" + fixdata['file_name'] + "',  \
						`file_type` = '" + fixdata['file_type'] + "',  \
						`sec_name` = '" + fixdata['sec_name'] + "',  \
						`key_name` = '" + fixdata['key_name'] + "',  \
						`include_type` = '" + fixdata['include_type'] + "',  \
						`include_priority` = '" + fixdata['include_priority'] + "',  \
						`include_type` = '" + fixdata['include_type'] + "'  \
						WHERE `id` = '" + fixdata['id'] + "' ;"
					
					// var jsonStr = JSON.stringify(fixdata);
					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql3).then(response => {
					// that.$axios.post(that.lpapi2, "form=do_sql&table=LP_account_list&updata="+ jsonStr).then(response => {
						if (response.status = 200) {
							that.$message({
								type: 'success',
								message: '修改成功!',
							});
							that.visible2 = false;
							that.$forceUpdate();
						} else {
							that.visible2 = false;
							that.$message({
								showClose: true,
								message: response.data,
								duration: 4000,
								type: 'error'
							});
						}
					})
				
				}).catch(() => {
					that.$message({
						type: 'info',
						message: '已取消修改'
					});
				});
				
				
				
				
			},
			delete_account(index, row) {
				var that = this
				if (this.allow_readpw!='yes' ){
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',inputType: 'password',
						inputType: 'password',
					}).then(({
						value
					}) => {
						if (value == '621890') {
							this.$message({
								type: 'success',
								message: '密码正确:'
							});
							that.allow_readpw='yes'
						} else {
							this.$message({
								type: 'error',
								message: '密码出错'
							});
						}
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});
					});
					return
				}
				let sql2 = " delete  from  `check_key_consistency`  where id='"+row.id+"';"

				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						that.$message({
							message: '删除完成',
							type: 'success'
						});
						that.server_choice=''
						that.get_exchange_arrange()
						that.$forceUpdate();
					} else {
						this.$message({
							message: '删除失败',
							type: 'error'
						});
						console.log(response.data);
					}
				})


			},
			addnew_account() {
				var that = this
				if (this.allow_readpw!='yes' ){
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',inputType: 'password',
						inputType: 'password',
					}).then(({
						value
					}) => {
						if (value == '621890') {
							this.$message({
								type: 'success',
								message: '密码正确:'
							});
							that.allow_readpw='yes'
						} else {
							this.$message({
								type: 'error',
								message: '密码出错'
							});
						}
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});
					});
					return
				}
				let sql2 = "REPLACE INTO `check_key_consistency`  (`update_time`) \
				VALUES ( CURRENT_TIMESTAMP  );"

				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						that.$message({
							message: '新增完成',
							type: 'success'
						});
						that.server_choice=''
						that.get_exchange_arrange()
						that.$forceUpdate();
					} else {
						this.$message({
							message: '新增失败',
							type: 'error'
						});
						console.log(response.data);
					}
				})


			},

			
		
		},
	}
</script>

<style>
	.el-table .bacOrangeRed {
		background: OrangeRed;
	}

	.el-table .bacorange {
		background: orange;
	}

	.el-table .success-row {
		background: grey;
		color: white;
	}

	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.el-table .grey {
		background: Silver;
	}

	.el-table .DarkGray {
		background: DarkGray;
	}

	.el-table .LightCoral {
		background: LightCoral;
		color: white;
	}

	.el-table .LimeGreen {
		background: LimeGreen;
	}

	.el-table .green {
		background: green;
	}

	.el-table .LightSlateGray {
		background: LightSlateGray;
	}

	.el-table .red {
		background: red;
		color: white;
	}

	.el-table .orange {
		background: NavajoWhite;
		color: black;
	}

	.el-table .blue {
		background: blue;
	}

	.el-table .purple {
		background: Violet;
		color: black;
	}

	.el-table .LightSteelBlue {
		background: LightSteelBlue;
	}

	.el-table .Goldenrod {
		background: Goldenrod;
	}

	.el-table .xingmu {
		background: Goldenrod;
		color: red;
		font-weight: bold;

	}


	.el-table .black {
		background: black;
		color: white;
	}

	.el-table .green {
		background: green;
		color: white;
	}

	.el-table .CornflowerBlue {
		background: CornflowerBlue;
		color: white;
	}

	.el-table .DodgerBlue {
		background: DodgerBlue;
	}
</style>
